package demo.vo;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;


public class StatDataPoint implements Serializable {
	
    private static final long serialVersionUID = 536020151313543741L;
    
	private String metric;
    private long timestamp;
    private String value;
    private Map<String, String> tags;
    private String valueType = ValueType.LONG.type;
    private long createdAt;
    private long sampleClientTime;
    private long sampleServerTime;
    
    private List<String> errorSpanIds;
	private Long maxResponseTime;
	private String spanId;
	private String monitorId;
	private String traceId;
	private String key; //just for sample compenstaion

    public StatDataPoint() {
        this.timestamp = getTimeZone(60*1000l);

    }

    public StatDataPoint(long zoneSpan) {
        this.timestamp = getTimeZone(zoneSpan);

    }

    public long getTimeZone(long zoneSpan){
        long time = System.currentTimeMillis();
        return time - time % zoneSpan ;
    }

    public StatDataPoint(String metric, long timestamp, long value, Map<String, String> tags) {
        this();
        this.metric = metric;
        this.timestamp = timestamp;
        this.value = String.valueOf(value);
        this.tags = tags;
        this.valueType = ValueType.LONG.type;
    }

    public StatDataPoint(String metric, long timestamp, long value, Map<String, String> tags, long sampleClientTime, long sampleServerTime) {
        this(metric, timestamp, value,tags);
        this.sampleClientTime = sampleClientTime;
        this.sampleServerTime = sampleServerTime;
    }

    public StatDataPoint(String metric, long timestamp, float value, Map<String, String> tags) {
        this();
        this.metric = metric;
        this.timestamp = timestamp;
        this.value = String.valueOf(value);
        this.tags = tags;
        this.valueType = ValueType.FLOAT.type;
    }

    public StatDataPoint(String metric, long timestamp, float value, Map<String, String> tags, long sampleClientTime, long sampleServerTime) {
        this(metric, timestamp, value,tags);
        this.sampleClientTime = sampleClientTime;
        this.sampleServerTime = sampleServerTime;

    }

    public StatDataPoint(String metric, long timestamp, double value, Map<String, String> tags) {
        this();
        this.metric = metric;
        this.timestamp = timestamp;
        this.value = new DecimalFormat("0.00").format(value);//String.valueOf(value);
        this.tags = tags;
        this.valueType = ValueType.DOUBLE.type;
    }

    public StatDataPoint(String metric, long timestamp, double value, Map<String, String> tags, long sampleClientTime, long sampleServerTime) {
        this(metric, timestamp, value,tags);
        this.sampleClientTime = sampleClientTime;
        this.sampleServerTime = sampleServerTime;

    }

    public ValueType getValueType() {
        return ValueType.valueOf(valueType.toUpperCase());
    }

    public void setValueType(ValueType valueType) {
        this.valueType = valueType.type;
    }

    public String getMetric() {
        return metric;
    }

    public void setMetric(String metric) {
        this.metric = metric;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Map<String, String> getTags() {
        return tags;
    }

    public void setTags(Map<String, String> tags) {
        this.tags = tags;
    }

    public long getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(long createdAt) {
        this.createdAt = createdAt;
    }

    public long getSampleClientTime() {
        return sampleClientTime;
    }

    public void setSampleClientTime(long sampleClientTime) {
        this.sampleClientTime = sampleClientTime;
    }

    public long getSampleServerTime() {
        return sampleServerTime;
    }

    public void setSampleServerTime(long sampleServerTime) {
        this.sampleServerTime = sampleServerTime;
    }

    public long longValue() {
        return Long.valueOf(value);
    }

    public double doubleValue() {
        return Double.valueOf(value);
    }

    public float floatValue() {
        return Float.valueOf(value);
    }

    public static enum ValueType {
        LONG("Long"),
        FLOAT("Float"),
        DOUBLE("Double");


        private final String type;

        ValueType(final String type) {
            this.type = type;
        }

        public String getType() {
            return type;
        }
    }

    
	/**
	 * @return the errorSpanIds
	 */
	public List<String> getErrorSpanIds() {
	
		return errorSpanIds;
	}

	
	/**
	 * @param errorSpanIds the errorSpanIds to set
	 */
	public void setErrorSpanIds(List<String> errorSpanIds) {
	
		this.errorSpanIds = errorSpanIds;
	}

	
	/**
	 * @return the maxResponseTime
	 */
	public Long getMaxResponseTime() {
	
		return maxResponseTime;
	}

	
	/**
	 * @param maxResponseTime the maxResponseTime to set
	 */
	public void setMaxResponseTime(Long maxResponseTime) {
	
		this.maxResponseTime = maxResponseTime;
	}

	
	/**
	 * @return the spanId
	 */
	public String getSpanId() {
	
		return spanId;
	}

	
	/**
	 * @param spanId the spanId to set
	 */
	public void setSpanId(String spanId) {
	
		this.spanId = spanId;
	}

	
	/**
	 * @return the monitorId
	 */
	public String getMonitorId() {
	
		return monitorId;
	}

	
	/**
	 * @param monitorId the monitorId to set
	 */
	public void setMonitorId(String monitorId) {
	
		this.monitorId = monitorId;
	}

	
	/**
	 * @return the traceId
	 */
	public String getTraceId() {
	
		return traceId;
	}
	

	
	
	/**
	 * @return the key
	 */
	public String getKey() {
	
		return key;
	}

	
	/**
	 * @param key the key to set
	 */
	public void setKey(String key) {
	
		this.key = key;
	}

	/**
	 * @param traceId the traceId to set
	 */
	public void setTraceId(String traceId) {
	
		this.traceId = traceId;
	}

}
